<template>
  <div class="app-container">
    <!--工具栏-->
    <Search :crud="crud">
      <el-form-item label="设备名称">
        <el-input
          v-model="query.equipmentManagementName"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="设备号码">
        <el-input
          v-model="query.equipmentManagementNumber"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
    </Search>
    <el-card>
      <div class="head-container">
        <crudOperation :permission="permission">
          <template slot="right">
            <el-button
              class="filter-item"
              size="mini"
              type="primary"
              icon="el-icon-plus"
              @click="handle(null, 'add')"
              >新增</el-button
            >
          </template>
        </crudOperation>
      </div>
      <el-table
        ref="table"
        border
        v-loading="crud.loading"
        :data="crud.data"
        style="width: 100%"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
          fixed="left"
        />
        <el-table-column label="序号" type="index" width="50" align="center" />
        <el-table-column
          prop="equipmentManagementName"
          label="设备名称"
          align="center"
        />
        <el-table-column
          prop="equipmentManagementNumber"
          label="设备号码"
          align="center"
        />
        <el-table-column
          prop="equipmentManagementType"
          label="设备型号"
          align="center"
        >
          <template slot-scope="scope">
            {{ dict.label.DEVICE_TYPE[scope.row.equipmentManagementType] }}
          </template>
        </el-table-column>
        <el-table-column prop="shopName" label="测试店铺" align="center" />

        <el-table-column prop="createdByName" label="创建人" align="center" />
        <el-table-column
          prop="createdAtView"
          label="创建日期"
          width="150"
          align="center"
        />
        <el-table-column label="操作" align="center" width="280" fixed="right">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="handle(scope.row, 'edit')"
              >修改</el-button
            >
            <el-button
              type="primary"
              size="mini"
              @click="handle(scope.row, 'bindMall')"
              >绑定店铺</el-button
            >
            <el-button
              type="danger"
              size="mini"
              @click="handle(scope.row, 'del')"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!--分页组件-->
      <pagination />
    </el-card>
    <AddOrEditDialog
      ref="AddOrEditDialogRef"
      :successAfter="crud.refresh"
    ></AddOrEditDialog>
    <bindMallDialog
      ref="bindMallDialogRef"
      :submitSuccess="crud.refresh"
    ></bindMallDialog>
  </div>
</template>

<script>
import APIObj from '@/api/deviceManage/index.js'
import CRUD, { presenter, header, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import udOperation from '@crud/UD.operation'
import Search from '@/components/Search'
import AddOrEditDialog from './components/AddOrEditDialog.vue'
import bindMallDialog from './components/bindMallDialog.vue'
import { showDictValue } from '@/utils'
export default {
  name: 'BrandIntroductionManage',
  components: {
    crudOperation,
    pagination,
    udOperation,
    Search,
    AddOrEditDialog,
    bindMallDialog,
  },
  cruds() {
    return CRUD({
      title: '店铺管理',
      url: 'equipmentManagement/list',
      requestMethod: 'post',
      sort: ['id,desc'],
    })
  },
  dicts: ['DEVICE_TYPE'],
  mixins: [presenter(), header(), crud()],
  data() {
    return {
      permission: {
        add: ['admin', 'job:add'],
        edit: ['admin', 'job:edit'],
        del: ['admin', 'job:del'],
      },
    }
  },
  methods: {
    showDictValue,
    // 改变状态
    changeEnabled(data, val) {
      product
        .tbDemoMoldTakingUpdateStatus({ id: data.id, isRelease: val })
        .then(() => {
          this.$notify({ message: '操作成功', type: 'success' })
          this.crud.refresh()
        })
        .catch((err) => {
          data.isRelease = !data.isRelease
          if (data.isRelease == '1') {
            data.isRelease = '0'
          } else {
            data.isRelease = '1'
          }
        })
    },
    // 删除与修改事件
    handle(row, type) {
      if (type == 'add') {
        this.$refs.AddOrEditDialogRef.handleOpen(type)
      } else if (type == 'edit') {
        this.$refs.AddOrEditDialogRef.handleOpen(type, row)
      } else if (type == 'improt') {
        this.$refs.UploadPointsRef.visible = true
      } else if (type == 'del') {
        this.deleteHandle(row)
      } else if (type === 'bindMall') {
        this.$refs.bindMallDialogRef.handleOpen(row)
      }
    },
    // 删除
    deleteHandle(params) {
      this.$confirm('确定删除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        APIObj.deleteHandle(params)
          .then((res) => {
            this.$notify({ message: '操作成功', type: 'success' })
            this.crud.refresh()
          })
          .catch(() => {})
      })
    },
    // 新建取模成功
    submitSuccess() {
      this.crud.refresh()
    },
  },
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-input-number .el-input__inner {
  text-align: left;
}
.item {
  margin-top: 10px;
  margin-right: 10px;
}
</style>
